package rc.jdbc.simple;

import java.sql.*;
public class SimpleJdbc {
	
	public static void main(String[] args)
		throws SQLException, ClassNotFoundException{
		//Load the JDBC driver
		Class.forName("com.mysql.jdbc.Driver");
		System.out.println("Driver loaded");
        
        // Establih a connection
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/dealerLocations", "java", "java");
        System.out.println("Database connected");
        
        // Create a statement
        Statement statement = connection.createStatement();
        
        // Execute a statement
        ResultSet resultSet = statement.executeQuery("select distinct city, country, state From dealers order by city");
        
        // Iterate through the result and print the student names
        while(resultSet.next()){
        	System.out.print(resultSet.getString(1) + "\t" + resultSet.getString(2) + "\t" + resultSet.getString(3) + "\n");
        }
        
        //Close the connection
        connection.close();
		}
	}

